package com.selfdriving.activity;

import java.io.IOException;
import java.util.Date;
import net.tsz.afinal.annotation.view.ViewInject;
import com.selfdriving.R;
import com.selfdriving.dialog.ChoosePictureDialog;
import com.selfdriving.utils.BitmapUtil;
import com.selfdriving.utils.LogUtil;
import com.selfdriving.view.CircularImage;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class PersonInfoActivity extends BaseActivity {
	@ViewInject(id = R.id.ivIcon,click="ivIcon")
	CircularImage ivIcon;
	
	@ViewInject(id=R.id.ivSkin,click="ivSkin")
	ImageView ivSkin;

	@ViewInject(id = R.id.tv1)
	TextView tv1;

	@ViewInject(id = R.id.tv2)
	TextView tv2;

	@ViewInject(id = R.id.tv3)
	TextView tv3;
	
	private ChoosePictureDialog choosePictureDialog;
	
	private static Uri imageCaptureUri;
	
	private Bitmap uploadBitmap = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.person_info);
		ivIcon.setImageResource(R.drawable.person_icon_2);
		tv1.setText("327" + "\n" + "关注");
		tv2.setText("327" + "\n" + "粉丝");
		tv3.setText("327" + "\n" + "返利");
		choosePictureDialog= new ChoosePictureDialog(this);
	}
	
	public void ivIcon(View v){
		choosePictureDialog.show();
	}
	
	public void ivSkin(View v){
		Intent intent = new Intent(this,ChangeSkinActivity.class);
		startActivity(intent);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode != Activity.RESULT_OK)
			return;
		Bundle extras = null;
		switch (requestCode) {
		case ChoosePictureDialog.PICK_FROM_FILE:
			LogUtil.i("PICK_FROM_FILE");
			setImageCaptureUri(data.getData());
			BitmapUtil.doCrop(this, getImageCaptureUri(),
					ChoosePictureDialog.CHOOSE_FROM_FILE);
			break;
		case ChoosePictureDialog.CROP_FROM_FILE:
			LogUtil.i("CROP_FROM_FILE");
			extras = data.getExtras();
			if (extras != null) {
				uploadBitmap = extras.getParcelable("data");
				ivIcon.setImageBitmap(uploadBitmap);
			}
			break;
		case ChoosePictureDialog.PICK_FROM_CAMERA:
			LogUtil.i("PICK_FROM_CAMERA");
			BitmapUtil.doCrop(this, getImageCaptureUri(),
					ChoosePictureDialog.CHOOSE_FROM_CAMERA);
			break;
		case ChoosePictureDialog.CROP_FROM_CAMERA:
			LogUtil.e("CROP_FROM_CAMERA");
			extras = data.getExtras();
			if (extras != null) {
				uploadBitmap = extras.getParcelable("data");
				ivIcon.setImageBitmap(uploadBitmap);
			}
			break;
		}
	}
	
	public static Uri getImageCaptureUri() {
		return imageCaptureUri;
	}

	public static void setImageCaptureUri(Uri imageCaptureUri) {
		PersonInfoActivity.imageCaptureUri = imageCaptureUri;
	}

}
